home *** CD-ROM | disk | FTP | other *** search
- /*
- ** CTCPResolverCall.h
- **
- ** TurboTCP support library
- ** TCP resolver class
- **
- ** Copyright © 1993, FrostByte Design / Eric Scouten
- **
- */
-
-
- #pragma once
-
- #ifndef TurboTCPHeaders
- #include <CObject.h>
- #include <CCollaborator.h>
- #include <MacTCPCommonTypes.h>
- #include "TurboTCP.const.h"
- #endif
-
-
- // reason codes for TCP resolver call notifications
-
- enum {
- tcpResolverStrToAddr, // StrToAddr completed info = (struct hostInfo *)
- tcpResolverAddrToName, // AddrToName completed info = (struct hostInfo *)
- tcpResolverHInfo, // HInfo completed info = (struct returnRec *)
- tcpResolverMXInfo, // MXInfo completed info = (struct returnRec *)
-
- tcpResolverLastChange = tcpResolverMXInfo
- };
-
-
- /*
- ** A modified version of <AddressXlation.h> is included here since none of the procedures
- ** of dnr.c are used. (The functionality is instead included in the CTCPResolverCall.cp file.)
- ** This version includes all of the typedefs, but omits the procedural definitions.
- */
-
- #define NUM_ALT_ADDRS 4
-
- typedef OSErr (*DNRProcPtr) (long, ...);
- typedef ProcPtr EnumResultProcPtr;
- typedef ProcPtr ResultProcPtr;
- typedef ProcPtr ResultProc2Ptr;
-
- typedef struct hostInfo {
- long rtnCode;
- char cname [255];
- unsigned long addr [NUM_ALT_ADDRS];
- };
-
- typedef enum AddrClasses {
- A = 1,
- NS,
- CNAME = 5,
- HINFO = 13,
- MX = 15,
- lastClass = 32767
- } AddrClasses;
-
- typedef struct HInfoRec {
- char cpuType [30];
- char osType [30];
- };
-
- typedef struct MXRec {
- unsigned short preference;
- char exchange [255];
- };
-
- typedef struct returnRec {
- short rtnCode;
- char cname [255];
- union {
- unsigned long addr [NUM_ALT_ADDRS];
- struct HInfoRec hinfo;
- struct MXRec mx;
- } rdata;
- };
-
- typedef struct cacheEntryRecord {
- char *cname;
- unsigned short type;
- unsigned short cacheClass;
- unsigned long ttl;
- union {
- char *name;
- ip_addr addr;
- } rdata;
- };
-
-
- // notification types for PostponeNotify()
-
- typedef enum {
- notifNone,
- notifStrToAddr,
- notifAddrToName,
- notifHInfo,
- notifMXInfo
- } NotifType;
-
-
- /*______________________________________________________________________
- **
- ** CTCPResolverCall
- **
- ** This class implements the core DNR calls. It is like the CTCPAsyncCall in that the call
- ** object is created to allow the call to persist beyond the scope of originating method.
- ** However, access to this object is not restricted; your application classes can and often
- ** will interact with the CTCPResolverCall object.
- **
- ** IMPORTANT: This object is a descendant of CCollaborator. Your application class should
- ** make itself a dependent of this object so that it may receive notification of resolver
- ** call completions.
- **
- ** Each resolver object may support only one asynchronous resolver call at a time.
- ** You may create several resolver objects to simultaneously process several calls,
- ** so long as you respect MacTCP’s limit of 8 resolver calls open at once. The CTCPDriver
- ** acts as a referee to prohibit more than 8 simultaneous calls.
- **
- ** One set of methods (Do...) is called to initiate resolver calls. These are the methods you
- ** will typically call from your application classes. These methods initiate asynchronous
- ** calls to the DNR code resource. When the calls are completed, the notification is passed
- ** to another set of methods (Handle...). The Handle… methods return notification to your
- ** class by means of the BroadcastChange mechanism. The exception to this is the DoAddrToStr
- ** method which returns the result immediately.
- **
- ** The userDataPtr fields of each of the calls are used by the resolver object to get
- ** notification of completion, and are not available to the caller.
- **
- ** The CTCPDriver object takes care of opening and closing the DNR code resource; it uses
- ** the OpenResolver and CloseResolver methods. You should not call these methods from your
- ** application classes.
- **
- ** The EnumCache call is not implemented in TurboTCP.
- **
- */
-
- class CTCPResolverCall : public CCollaborator {
-
- protected:
- Boolean inUse; // resolver in use; can’t accept calls
- Boolean disposeOnCompletion; // dispose of resolver call once completed
- struct hostInfo theHostInfo; // parms for StrToAddr
- struct returnRec theHMXInfo; // parms for HInfo or MXInfo
- char hostName [255]; // name of user host
- NotifType pendingNotify; // resolver is in ProcessNotify queue
- static Handle macDNRcode; // the DNR code resource’s handle
- static DNRProcPtr macDNRentry; // the DNR code entry point
- TurboTCPQElem qEntry; // completion queue entry
-
-
- // initialize/destroy resolver
-
- public:
- void ITCPResolverCall (void);
- virtual void Dispose (void);
-
-
- // initiate resolver calls
-
- void DoStrToAddr (char *theHostName);
- void DoAddrToStr (ip_addr theIPaddr, char *theString);
- void DoAddrToName (ip_addr theIPaddr);
- void DoHInfo (char *theHostName);
- void DoMXInfo (char *theHostName);
-
-
- // respond to completion of resolver calls
-
- virtual void ProcessNotify (void);
- protected:
- virtual void HandleStrToAddr (void);
- virtual void HandleAddrToName (void);
- virtual void HandleHInfo (void);
- virtual void HandleMXInfo (void);
-
-
- // open/close TCP resolver
-
- public:
- static void OpenResolver (void);
- static void CloseResolver (void);
- protected:
- static short OpenTheDNR (void);
- static short SearchFolderForDNRP (long targetType, long targetCreator,
- short vRefNum, long dirID);
- static void GetSystemFolder (short *vRefNumP, long *dirIDP);
- static void GetCPanelFolder (short *vRefNumP, long *dirIDP);
-
-
- // interrupt-level methods: delay processing for non-interrupt status
-
- virtual void PostponeNotify (NotifType theNotifType);
- static pascal void PostponeStrToAddr (struct hostInfo *hostInfoPtr, char *userDataPtr);
- static pascal void PostponeAddrToName (struct hostInfo *hostInfoPtr, char *userDataPtr);
- static pascal void PostponeHInfo (struct returnRec *returnRecPtr, char *userDataPtr);
- static pascal void PostponeMXInfo (struct returnRec *returnRecPtr, char *userDataPtr);
-
- };
-